import httpapi from "../utils/httpapi"
import lodash from 'lodash'
const apipath = {
    getcolumntree: "/frontend/getcolumntree",
    loadbloglist: "/frontend/blog/getbloglist",
    loadblogdetail: "/frontend/blog/getblogdetail",
    loglikeblog: "/frontend/blog/loglikeblog",
    gethotbloglist: "/frontend/blog/gethotbloglist",
    getclientsettings: "/frontend/blog/getclientsettings"
};

export function getNaviMenu (langid, success, failure) {
    if(lodash.isNil(langid)) langid = 0;
    httpapi.get(
        apipath.getcolumntree,
        { langid: langid },
        success,
        failure
    );
}

export function getBlogList (columnid, page, pagesize, success, failure) {
    httpapi.get(
        apipath.loadbloglist,
        { cid: columnid, page: page, pagesize: pagesize },
        success,
        failure
    );
}

export function getBlogDetail (blogid, columnid, success, failure) {
    httpapi.get(
        apipath.loadblogdetail,
        { bid: blogid, cid: columnid },
        success,
        failure
    );
}

export function logLikeBlog (blogid, success, failure) {
    httpapi.post(
        apipath.loglikeblog,
        blogid,
        success,
        failure
    );
}

export function getHotBlogList (langid, top, success, failure) {
    httpapi.get(
        apipath.gethotbloglist,
        { langid: langid, top: top },
        success,
        failure
    );
}

export function getClientSettings (clientmode, success, failure) {
    httpapi.post(
        apipath.getclientsettings,
        clientmode,
        success,
        failure
    );
}
/**
 * for timeago.js
 */
export function getLanguageSupport(language) {
    let local = 'zh_CN';
    switch(language) {
        case 'zh':
          local = "zh_CN";
          break;
        case 'en' : 
          local = "en_US";
          break;
        default:
          local = 'zh_CN';
          break;
    }
    return local;
}